import {
  createRouter,
  createWebHistory,
  RouteRecordRaw,
  Router
} from 'vue-router';

const title: string = 'One Admin Vue';

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    meta: {
      title: `${title} - 登录`
    },
    component: () => import(/* webpackChunkName: "login" */ '../pages/login')
  }
];

const router: Router = createRouter({
  routes,
  history: createWebHistory()
});

router.beforeEach(guard => {
  document.title = (guard.meta.title || title) as string;
});

export default router;
